package com.grid.camera.examples;

import com.grid.camera.pelco.PelcoDProtocol;
import com.grid.camera.pelco.PelcoDResponseValidator;

/** PelcoDResponseValidator测试类 演示如何使用PelcoDResponseValidator验证响应 */
public class PelcoDResponseValidatorTest {

    public static void main(String[] args) {
        // 创建一个请求命令
        int deviceAddress = 1;
        byte[] request = PelcoDProtocol.moveUp(deviceAddress);

        // 假设响应与请求相同
        byte[] sameResponse = request.clone();

        // 假设响应与请求不同
        byte[] differentResponse = PelcoDProtocol.moveDown(deviceAddress);

        // 使用exactMatch验证器
        boolean exactMatchResult1 = PelcoDResponseValidator.exactMatch(request).test(sameResponse);
        boolean exactMatchResult2 =
                PelcoDResponseValidator.exactMatch(request).test(differentResponse);

        System.out.println("请求和相同响应的exactMatch结果: " + exactMatchResult1); // 应该是true
        System.out.println("请求和不同响应的exactMatch结果: " + exactMatchResult2); // 应该是false

        // 使用addressMatch验证器
        boolean addressMatchResult1 =
                PelcoDResponseValidator.addressMatch(request).test(sameResponse);
        boolean addressMatchResult2 =
                PelcoDResponseValidator.addressMatch(request).test(differentResponse);

        System.out.println("请求和相同响应的addressMatch结果: " + addressMatchResult1); // 应该是true
        System.out.println("请求和不同响应的addressMatch结果: " + addressMatchResult2); // 应该是true，因为设备地址相同

        // 演示如何在PelcoDEnhancedClient中使用验证器
        System.out.println("\n在PelcoDEnhancedClient中使用验证器的示例代码:");
        System.out.println(
                "client.executeCommand(command, PelcoDResponseValidator.exactMatch(command));");
    }
}
